package com.miyake.loveviewweb.server.service;

import java.util.List;

import org.slim3.datastore.Datastore;

import com.google.appengine.api.datastore.Key;
import com.google.appengine.api.users.User;
import com.google.appengine.api.users.UserService;
import com.google.appengine.api.users.UserServiceFactory;
import com.miyake.loveviewweb.server.meta.UserModelMeta;

public class MyUserKey {
    public static Key get() {
        UserService userService = UserServiceFactory.getUserService();
        User user = userService.getCurrentUser();
        
        UserModelMeta ue = UserModelMeta.get();
        List<Key> list = Datastore.query(ue).filter(ue.userID.equal(user.getUserId())).asKeyList();
        if (list.size() == 1) {
            return list.get(0);
        }
        return null;
    }
    
    public static String getGoogleUserId() {
        UserService userService = UserServiceFactory.getUserService();
        User user = userService.getCurrentUser();
        return user.getUserId();
    }
}
